public class TitleToNumber {

    public int titleToNumber(String columnTitle) {
        int n = columnTitle.length();
        if (n == 1) return columnTitle.charAt(0) - 64;
        char[] chars = columnTitle.toCharArray();
        int ans = 0;
        for (int i = 0; i < n; i++) {
            ans += (chars[i] - 64) * Math.pow(26, n - i - 1);
        }
        return ans;
    }
}
